import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:xindong/common/xindong_methods.dart';
import 'package:xindong/routes/call/controller/xindong_call_rtc_network_ctr.dart';

// 通话网络状态
class XinDongCallRTCNetworkShiTu extends StatelessWidget {
  static TextStyle textStyle = const TextStyle(fontSize: 10, fontWeight: FontWeight.normal, color: Colors.white);

  const XinDongCallRTCNetworkShiTu({Key? key}) : super(key: key);

  List generateData(int quality) {
    Color? color;
    String? text;
    switch (quality) {
      case 0:
      case 1:
        color = Colors.greenAccent[400];
        text = "优";
        break;
      case 2:
        color = Colors.green;
        text = "好";
        break;
      case 3:
        color = Colors.amber;
        text = "一般";
        break;
      case 4:
      case 5:
        color = Colors.orange;
        text = "很差";
        break;
      default:
        color = Colors.red;
        text = "X";
        break;
    }
    return [color, text];
  }

  @override
  Widget build(BuildContext context) {
    return GestureDetector(
      onLongPress: () => showToast("网络质量比较：优 > 好 > 一般 > 很差", milliseconds: 3000),
      behavior: HitTestBehavior.opaque,
      child: Container(
        padding: const EdgeInsets.only(left: 10, top: 8),
        child: GetBuilder<XinDongCallRTCNetworkController>(
          builder: (controller) {
            int localNetworkQuality = controller.localNetworkQuality;
            int remoteNetworkQuality = controller.remoteNetworkQuality;
            List localData = generateData(localNetworkQuality);
            List remoteData = generateData(remoteNetworkQuality);
            return Row(
              mainAxisSize: MainAxisSize.min,
              children: [
                buildContainerMineNetwork(localData, remoteData),
              ],
            );
          },
        ),
      ),
    );
  }

  buildContainerMineNetwork(List localData, List remoteData) {
    return Column(
      crossAxisAlignment: CrossAxisAlignment.start,
      children: [
        Row(
          mainAxisSize: MainAxisSize.min,
          children: [
            Text.rich(
              TextSpan(text: "我的网络：", children: [
                TextSpan(text: "${localData.last}", style: TextStyle(color: localData.first)),
              ]),
              style: textStyle,
            ),
            const SizedBox(width: 2),
          ],
        ),
        Text.rich(
          TextSpan(text: "对方网络：", children: [
            TextSpan(text: "${remoteData.last}", style: TextStyle(color: remoteData.first)),
          ]),
          style: textStyle,
        ),
      ],
    );
  }
}
